﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using Pharmacy.Entities;
using Pharmacy.Data;

#endregion

namespace Pharmacy.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="ViewRequiredAdjustmentProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class ViewRequiredAdjustmentProviderBaseCore : EntityViewProviderBase<ViewRequiredAdjustment>
	{
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;ViewRequiredAdjustment&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;ViewRequiredAdjustment&gt;"/></returns>
		protected static VList&lt;ViewRequiredAdjustment&gt; Fill(DataSet dataSet, VList<ViewRequiredAdjustment> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<ViewRequiredAdjustment>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;ViewRequiredAdjustment&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<ViewRequiredAdjustment>"/></returns>
		protected static VList&lt;ViewRequiredAdjustment&gt; Fill(DataTable dataTable, VList<ViewRequiredAdjustment> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					ViewRequiredAdjustment c = new ViewRequiredAdjustment();
					c.RequirementId = (Convert.IsDBNull(row["RequirementId"]))?(long)0:(System.Int64?)row["RequirementId"];
					c.DrugId = (Convert.IsDBNull(row["DrugId"]))?string.Empty:(System.String)row["DrugId"];
					c.DrugName = (Convert.IsDBNull(row["DrugName"]))?string.Empty:(System.String)row["DrugName"];
					c.Quantity = (Convert.IsDBNull(row["Quantity"]))?(int)0:(System.Int32?)row["Quantity"];
					c.AdjustQuantity = (Convert.IsDBNull(row["AdjustQuantity"]))?(int)0:(System.Int32)row["AdjustQuantity"];
					c.FinalQuantity = (Convert.IsDBNull(row["FinalQuantity"]))?(int)0:(System.Int32?)row["FinalQuantity"];
					c.Remark = (Convert.IsDBNull(row["Remark"]))?string.Empty:(System.String)row["Remark"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;ViewRequiredAdjustment&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;ViewRequiredAdjustment&gt;"/></returns>
		protected VList<ViewRequiredAdjustment> Fill(IDataReader reader, VList<ViewRequiredAdjustment> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					ViewRequiredAdjustment entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<ViewRequiredAdjustment>("ViewRequiredAdjustment",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new ViewRequiredAdjustment();
					}
					
					entity.SuppressEntityEvents = true;

					entity.RequirementId = (reader.IsDBNull(((int)ViewRequiredAdjustmentColumn.RequirementId)))?null:(System.Int64?)reader[((int)ViewRequiredAdjustmentColumn.RequirementId)];
					//entity.RequirementId = (Convert.IsDBNull(reader["RequirementId"]))?(long)0:(System.Int64?)reader["RequirementId"];
					entity.DrugId = (System.String)reader[((int)ViewRequiredAdjustmentColumn.DrugId)];
					//entity.DrugId = (Convert.IsDBNull(reader["DrugId"]))?string.Empty:(System.String)reader["DrugId"];
					entity.DrugName = (System.String)reader[((int)ViewRequiredAdjustmentColumn.DrugName)];
					//entity.DrugName = (Convert.IsDBNull(reader["DrugName"]))?string.Empty:(System.String)reader["DrugName"];
					entity.Quantity = (reader.IsDBNull(((int)ViewRequiredAdjustmentColumn.Quantity)))?null:(System.Int32?)reader[((int)ViewRequiredAdjustmentColumn.Quantity)];
					//entity.Quantity = (Convert.IsDBNull(reader["Quantity"]))?(int)0:(System.Int32?)reader["Quantity"];
					entity.AdjustQuantity = (System.Int32)reader[((int)ViewRequiredAdjustmentColumn.AdjustQuantity)];
					//entity.AdjustQuantity = (Convert.IsDBNull(reader["AdjustQuantity"]))?(int)0:(System.Int32)reader["AdjustQuantity"];
					entity.FinalQuantity = (reader.IsDBNull(((int)ViewRequiredAdjustmentColumn.FinalQuantity)))?null:(System.Int32?)reader[((int)ViewRequiredAdjustmentColumn.FinalQuantity)];
					//entity.FinalQuantity = (Convert.IsDBNull(reader["FinalQuantity"]))?(int)0:(System.Int32?)reader["FinalQuantity"];
					entity.Remark = (System.String)reader[((int)ViewRequiredAdjustmentColumn.Remark)];
					//entity.Remark = (Convert.IsDBNull(reader["Remark"]))?string.Empty:(System.String)reader["Remark"];
					entity.AcceptChanges();
					entity.SuppressEntityEvents = false;
					
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="ViewRequiredAdjustment"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="ViewRequiredAdjustment"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, ViewRequiredAdjustment entity)
		{
			reader.Read();
			entity.RequirementId = (reader.IsDBNull(((int)ViewRequiredAdjustmentColumn.RequirementId)))?null:(System.Int64?)reader[((int)ViewRequiredAdjustmentColumn.RequirementId)];
			//entity.RequirementId = (Convert.IsDBNull(reader["RequirementId"]))?(long)0:(System.Int64?)reader["RequirementId"];
			entity.DrugId = (System.String)reader[((int)ViewRequiredAdjustmentColumn.DrugId)];
			//entity.DrugId = (Convert.IsDBNull(reader["DrugId"]))?string.Empty:(System.String)reader["DrugId"];
			entity.DrugName = (System.String)reader[((int)ViewRequiredAdjustmentColumn.DrugName)];
			//entity.DrugName = (Convert.IsDBNull(reader["DrugName"]))?string.Empty:(System.String)reader["DrugName"];
			entity.Quantity = (reader.IsDBNull(((int)ViewRequiredAdjustmentColumn.Quantity)))?null:(System.Int32?)reader[((int)ViewRequiredAdjustmentColumn.Quantity)];
			//entity.Quantity = (Convert.IsDBNull(reader["Quantity"]))?(int)0:(System.Int32?)reader["Quantity"];
			entity.AdjustQuantity = (System.Int32)reader[((int)ViewRequiredAdjustmentColumn.AdjustQuantity)];
			//entity.AdjustQuantity = (Convert.IsDBNull(reader["AdjustQuantity"]))?(int)0:(System.Int32)reader["AdjustQuantity"];
			entity.FinalQuantity = (reader.IsDBNull(((int)ViewRequiredAdjustmentColumn.FinalQuantity)))?null:(System.Int32?)reader[((int)ViewRequiredAdjustmentColumn.FinalQuantity)];
			//entity.FinalQuantity = (Convert.IsDBNull(reader["FinalQuantity"]))?(int)0:(System.Int32?)reader["FinalQuantity"];
			entity.Remark = (System.String)reader[((int)ViewRequiredAdjustmentColumn.Remark)];
			//entity.Remark = (Convert.IsDBNull(reader["Remark"]))?string.Empty:(System.String)reader["Remark"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="ViewRequiredAdjustment"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="ViewRequiredAdjustment"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, ViewRequiredAdjustment entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.RequirementId = (Convert.IsDBNull(dataRow["RequirementId"]))?(long)0:(System.Int64?)dataRow["RequirementId"];
			entity.DrugId = (Convert.IsDBNull(dataRow["DrugId"]))?string.Empty:(System.String)dataRow["DrugId"];
			entity.DrugName = (Convert.IsDBNull(dataRow["DrugName"]))?string.Empty:(System.String)dataRow["DrugName"];
			entity.Quantity = (Convert.IsDBNull(dataRow["Quantity"]))?(int)0:(System.Int32?)dataRow["Quantity"];
			entity.AdjustQuantity = (Convert.IsDBNull(dataRow["AdjustQuantity"]))?(int)0:(System.Int32)dataRow["AdjustQuantity"];
			entity.FinalQuantity = (Convert.IsDBNull(dataRow["FinalQuantity"]))?(int)0:(System.Int32?)dataRow["FinalQuantity"];
			entity.Remark = (Convert.IsDBNull(dataRow["Remark"]))?string.Empty:(System.String)dataRow["Remark"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region ViewRequiredAdjustmentFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="ViewRequiredAdjustment"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class ViewRequiredAdjustmentFilterBuilder : SqlFilterBuilder<ViewRequiredAdjustmentColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the ViewRequiredAdjustmentFilterBuilder class.
		/// </summary>
		public ViewRequiredAdjustmentFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the ViewRequiredAdjustmentFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public ViewRequiredAdjustmentFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the ViewRequiredAdjustmentFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public ViewRequiredAdjustmentFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion ViewRequiredAdjustmentFilterBuilder

	#region ViewRequiredAdjustmentParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="ViewRequiredAdjustment"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class ViewRequiredAdjustmentParameterBuilder : ParameterizedSqlFilterBuilder<ViewRequiredAdjustmentColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the ViewRequiredAdjustmentParameterBuilder class.
		/// </summary>
		public ViewRequiredAdjustmentParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the ViewRequiredAdjustmentParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public ViewRequiredAdjustmentParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the ViewRequiredAdjustmentParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public ViewRequiredAdjustmentParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion ViewRequiredAdjustmentParameterBuilder
	
	#region ViewRequiredAdjustmentSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="ViewRequiredAdjustment"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class ViewRequiredAdjustmentSortBuilder : SqlSortBuilder<ViewRequiredAdjustmentColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the ViewRequiredAdjustmentSqlSortBuilder class.
		/// </summary>
		public ViewRequiredAdjustmentSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion ViewRequiredAdjustmentSortBuilder

} // end namespace
